/*
 * This class should be the root of your parse tree.
 * 
 * Update the class with the variables and constructors
 * you see required.
 * 
 * Update the toString method to print the tree.
 * 
 * Update the check method such that it checks the
 * tree for semantic errors.
 */

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

public class ClassDecl 
{
	private String classId;
	MethodDecls methodDecls;
	
	public static String inFile;
	
	public ClassDecl(String id,MethodDecls mds) 
	{
		classId = id;
		methodDecls = mds;
	}
	
	public String toString()
	{
		String ret = "ClassDecl " +classId+ "\n";
		String ret2 = "";
		
		if(methodDecls != null)
		{
			ret2 += methodDecls.toString();
		}
	
		String result = "";
		for( String s: ret2.split("\n"))
		{
			ret += "| " +s + "\n";
		}
		return ret;
	}
	
	public void check() throws SemanticException {
		
		SymbolTable st = SymbolTable.getInstance();
		
		st.add(new Entry(classId, "Class", ""));
		
			st.openScope();
			
				methodDecls.check();
			
			st.closeScope();
		
	}
	
	public static String getLine(int number)
	{
		try
		{
			BufferedReader r = new BufferedReader(new FileReader(inFile));
			for(int i = 1 ; i< number ; i++)
			{
				r.readLine();
			}
			return r.readLine();
		}
		catch( Exception e )
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "NOTHING";
	}
}
